package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.domain.Tag;
import com.miku.blog.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author shkstart
 * @create ${}YEAR-05-30 3:26
 */
@Api(tags = "后台管理系统[标签]")
@RequestMapping("/admin")
@RestController
public class TagController {

    @Autowired
    private TagService tagService;

    @SystemLog(notes = "获取标签列表{后台管理系统}")
    @ApiOperation(value = "获取标签接口",notes = "获取文章标签列表")
    @GetMapping("/tags")
    public ResponseResult tags(@RequestParam("current")Integer current,
                               @RequestParam("size")Integer size,
                               @RequestParam(value = "keywords",required = false)String keywords)
    {
        return tagService.tags(current,size,keywords);
    }

    @SystemLog(notes = "添加或修改文章标签{后台管理系统}")
    @ApiOperation(value = "添加或修改标签接口",notes = "添加/修改文章标签")
    @PostMapping("/tags")
    public ResponseResult addTags(@RequestBody Tag tag){
        return tagService.addTags(tag);
    }

    @SystemLog(notes = "删除标签{后台管理系统}")
    @ApiOperation(value = "删除标签接口",notes = "删除文章标签列表 { 当该标签下无对应文章时 }")
    @DeleteMapping("/tags")
    public ResponseResult deleteTags(@RequestBody Integer[] tagIdList){
        return tagService.deleteTags(tagIdList);
    }



    @SystemLog(notes = "搜索文章标签{文章发布分类选项}{后台管理系统}")
    @ApiOperation(value = "搜索文章标签{文章发布分类选项}接口", notes = "搜索文章标签{文章发布分类选项} 支持自定义标签名称")
    @GetMapping("/tags/search")
    public ResponseResult getTagList(){
        return tagService.getTagList();
    }

}
